<template>
    <rx-dialog @ok="handRetrieveTask" @cancel="cancel" order="top" btnalign="right">
        <a-form ref="form" :model="form" layout="vertical" class="rx-a-form-vertical">
            <div style="font-size: 18px;color: #4d9eff;margin-bottom: 10px;">{{ subject }}</div>

            <a-form-item
                :label="i18n('fetchPage.opinion','意见')" name="opinion"
                :rules="[{ required: true, message: '意见必填!' }]"
            >
                <a-textarea v-model:value="form.opinion" style="width: 100%" :autosize="{minRows:3}"/>
            </a-form-item>

            <a-form-item :label="i18n('fetchPage.msgTypes','通知方式')" name="msgTypes">
                <a-checkbox-group v-model:options="msgOptions" v-model:value="form.msgTypes">
                </a-checkbox-group>
            </a-form-item>
        </a-form>
    </rx-dialog>
</template>

<script>
import {BaseFormModel, RxDialog, Util} from '@lowcode/jpaas-base-lib';
import myBpmApi from "@/views/modules/bpm/js/myBpm";

export default {
    name: "bpm-retrieve-task",
    props: {
        subject: String,
        taskId: String,
        layerid: String,
        lydata: Object,
        destroy: Function
    },
    mixins: [BaseFormModel],
    components: {
        RxDialog,
    },
    data() {
        return {
            msgOptions: [],
            form: {
                opinion: "",
                msgTypes: []
            },

        }
    },
    created() {
        this.init();
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "MyTransOutTask", key);
        },
        init() {
            this.form.taskId = this.taskId;
            myBpmApi.getMessageHandler().then(res => {
                res.forEach((val) => {
                    this.msgOptions.push({label: val.name, value: val.type})
                })
            })
        },
        handRetrieveTask(vm) {
            if(!this.form.opinion){
                this.$message.error('意见必填！');
                vm.loading = false ;
                return ;
            }
            this.handRetrieveTaskDialog(vm)
        },
        handRetrieveTaskDialog(vm) {
            this.form.msgTypes = this.form.msgTypes.join(",");
            var self = this;
            this.$confirm({
                title: this.$ti18('rxMsa.actionTips', '操作提示'),
                zIndex: 20000,
                content: self.i18n('msa.fetchTips', '确认取回代办任务吗?'),
                okText: this.$ti18('rxForm.ackBtn', '确认'),
                cancelText: this.$ti18('rxForm.cancelBtn', '取消'),
                onOk() {
                    if(!self.form.opinion){
                        self.$message.error('意见必填！');
                        vm.loading = false ;

                    }else {
                        myBpmApi.doRetrieveTask(self.form).then(res => {
                            vm.loading = false ;
                            Util.closeWindow(self, "ok")
                        })
                    }

                },
                onCancel() {
                    vm.loading = false;
                    self.form.msgTypes = self.form.msgTypes.split(",");
                }
            })
        }
    }
}
</script>

<style scoped>

</style>
